﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.Design;

namespace ODataSource
{
    // A custom View Schema class
    public class ODataSourceViewSchema : IDataSourceViewSchema
    {
        private ODesignDataSourceView oDesignDataSourceView;

        public ODataSourceViewSchema(ODesignDataSourceView oDesignDataSourceView)
        {
            // TODO: Complete member initialization
            this.oDesignDataSourceView = oDesignDataSourceView;
        }

        // The name of this View Schema
        public string Name
        {
            get { return "Schema"; }
        }

        // Build a Field Schema array
        public IDataSourceFieldSchema[] GetFields()
        {
            var Fields = oDesignDataSourceView.query.GetType().GetGenericArguments()[0].GetProperties();


            IDataSourceFieldSchema[] fields = new IDataSourceFieldSchema[Fields.Count()];
            for (int i = 0; i < Fields.Count(); i++)
            {
                fields[i] = new ODataSourceFieldSchema(Fields[i]);
            }
            return fields;
        }
        // There are no child views, so return null
        public IDataSourceViewSchema[] GetChildren()
        {
            return null;
        }
    }
}
